package com.mmy.acassistant.model.f2.ui.fragment

import android.annotation.SuppressLint
import android.graphics.Color
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import java.net.Socket
import kotlin.concurrent.thread

/**
 * @创建者     lucas
 * @创建时间   2017/12/27 0027 14:34
 * @描述          TODO
 */
class F2Fragment : Fragment() {
    @SuppressLint("ResourceAsColor")
    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val textView = TextView(activity)
        textView.text= "f2"
        textView.setBackgroundColor(Color.BLUE)
        textView.setTextColor(android.R.color.black)
        thread {
            val ip: String = "192.168.2.116"
            val port: Int = 5556
            val data: String = "test data test data test data test data"
            try {

                val socket = Socket(ip, port)
                val outputStream = socket.getOutputStream()
                outputStream.write(data.toByteArray())
                outputStream.flush()
                outputStream.close()
            }catch (e:Exception){
                e.printStackTrace()
            }
        }
        return textView
    }
}